home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / CBuilder / Setup / BCB / data.z / edorders.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-02-09  |  5.5 KB  |  160 lines

  1. //---------------------------------------------------------------------------
  2. // Borland C++Builder
  3. // Copyright (c) 1987, 1998 Borland International Inc.  All Rights Reserved.
  4. //---------------------------------------------------------------------------
  5. //---------------------------------------------------------------------------
  6. #include <vcl.h>
  7. #pragma hdrstop
  8.  
  9. #include <stdio.h>
  10. #include "edorders.h"
  11. #include "Datamod.h"
  12. #include "srchdlg.h"
  13. #include "pickdate.h"
  14. //---------------------------------------------------------------------------
  15. #pragma resource "*.dfm"
  16. TEdOrderForm *EdOrderForm;
  17. const char * DataSetStates[]={"Not active", "Browsing", "Editing", "Inserting", "", "", "", "", ""};
  18. const int HelpTopicEdit = 2;
  19. const int HelpTopicBrowse = 3;
  20. //---------------------------------------------------------------------------
  21. __fastcall TEdOrderForm::TEdOrderForm(TComponent* Owner)
  22.     : TForm(Owner)
  23. {
  24. }
  25.  
  26. void TEdOrderForm::Enter()
  27. {
  28.   MastData->OrdersSource->OnStateChange = OrdersSourceStateChange;
  29.   try
  30.   {
  31.     MastData->Orders->Open();
  32.     MastData->Orders->Insert();
  33.     ShowModal();
  34.   }
  35.   catch(...)  {
  36.     MastData->OrdersSource->OnStateChange = NULL;
  37.     return;
  38.   }
  39.   MastData->OrdersSource->OnStateChange = NULL;
  40. }
  41.  
  42. void TEdOrderForm::Edit(double OrderNo)
  43. {
  44.   MastData->OrdersSource->OnStateChange = OrdersSourceStateChange;
  45.   try
  46.   {
  47.     TLocateOptions  flags;
  48.     MastData->Orders->Open();
  49.     MastData->Orders->Locate("OrderNo", OrderNo, flags);
  50.     ShowModal();
  51.   }
  52.   catch (...)
  53.   {
  54.       MastData->OrdersSource->OnStateChange = NULL;
  55.       return;
  56.   }
  57.   MastData->OrdersSource->OnStateChange = NULL;
  58. }
  59.  
  60.  
  61. //---------------------------------------------------------------------------
  62. void __fastcall TEdOrderForm::ItemsGridEnter(TObject *Sender)
  63. {
  64.   ActiveSource->DataSet = MastData->Items;
  65. }
  66. //---------------------------------------------------------------------------
  67. // Update the mode indicator when the state of the "Active" datasource
  68. // (Orders or Items) changes.
  69. void __fastcall TEdOrderForm::ActiveSourceStateChange(TObject *Sender)
  70. {
  71.  // with ActiveSource do
  72.     if (ActiveSource->DataSet != NULL)
  73.     {
  74.       char MIcaption[80];
  75.       sprintf(MIcaption,"%s: %s",ActiveSource->DataSet->Name.c_str(),DataSetStates[ActiveSource->State]);
  76.       ModeIndicator->Caption=AnsiString(MIcaption);
  77.     }
  78.     if (ActiveSource->State==dsEdit || ActiveSource->State==dsInsert || ActiveSource->State==dsSetKey)
  79.     {
  80.       HelpContext = HelpTopicEdit;
  81.       ModeIndicator->Font->Color = clRed;
  82.     }
  83.     else
  84.     {
  85.       HelpContext = HelpTopicBrowse;
  86.       ModeIndicator->Font->Color = clBlue;
  87.     }
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TEdOrderForm::ItemsGridExit(TObject *Sender)
  91. {
  92.   ActiveSource->DataSet = MastData->Orders;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TEdOrderForm::CancelBtnClick(TObject *Sender)
  96. {
  97.   MastData->OrdersAfterCancel(MastData->Orders);
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TEdOrderForm::PostBtnClick(TObject *Sender)
  101. {
  102.   MastData->Orders->Post();
  103. }
  104. //---------------------------------------------------------------------------
  105. // Clicking on the PartNo button in the grid brings up PickPartNo dialog
  106. void __fastcall TEdOrderForm::PickPartNo(TObject *Sender)
  107. {
  108.   if (ItemsGrid->SelectedField == MastData->ItemsPartNo) //PartNo column only
  109.   {
  110.     if (MastData->ItemsPartNo->Value)
  111.       SearchDlg->PartNo = MastData->ItemsPartNo->Value;     //start with current PartNo
  112.     if (SearchDlg->ShowModalParts() == mrOk)
  113.     {
  114.       MastData->Items->Edit();
  115.       MastData->ItemsPartNo->Value = SearchDlg->PartNo;
  116.     }
  117.   }
  118. }
  119. //---------------------------------------------------------------------------
  120. // Browse a calendar to pick an invoice date
  121. void __fastcall TEdOrderForm::PickDate(TObject *Sender)
  122. {
  123.   BrDateForm->Date = MastData->OrdersSaleDate->Value;     //start with current date
  124.   if (BrDateForm->ShowModal() == mrOk)
  125.   {
  126.     MastData->Orders->Edit();
  127.     MastData->OrdersSaleDate->Value = BrDateForm->Date;
  128.     SaleDateEdit->SelectAll();
  129.   }
  130. }
  131. //---------------------------------------------------------------------------
  132. void __fastcall TEdOrderForm::PrintBtnClick(TObject *Sender)
  133. {
  134.   if(Confirm("Print image of this form window?"))
  135.     Print();
  136. }
  137. //---------------------------------------------------------------------------
  138. // Enable or disable buttons as needed when the state of the orders table changes
  139. void __fastcall TEdOrderForm::OrdersSourceStateChange(TObject * Sender)
  140. {
  141.   PostBtn->Enabled   = ((MastData->Orders->State==dsEdit) ||
  142.                         (MastData->Orders->State==dsInsert) ||
  143.                                 (MastData->Orders->State==dsSetKey));
  144.   CancelBtn->Enabled = PostBtn->Enabled;
  145.   CloseBtn->Enabled  = (MastData->Orders->State==dsBrowse);
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall TEdOrderForm::FormCloseQuery(TObject *Sender, bool &CanClose)
  149. {
  150.   CanClose = MastData->DataSetApplyUpdates(MastData->Orders, ModalResult == mrOk);
  151. }
  152. //---------------------------------------------------------------------------
  153. void __fastcall TEdOrderForm::SoldByComboKeyPress(TObject *Sender, char &Key)
  154. {
  155.   if (!((int)Key==13 || (int)Key==27))
  156.     Key = '0';
  157. }
  158. //---------------------------------------------------------------------------
  159.  
  160.